local M = require "packages/mamashengde/record/Made"

local susheng = fk.CreateSkill {
  name = "shine__susheng",
}

Fk:loadTranslationTable {
  ["shine__susheng"] = "苏生",
  [":shine__susheng"] = "当称号与你相同的角色进入濒死状态时，你可以消耗任意魔力令其回复等量的体力（若其不为你则额外回复等量魔力），然后你摸等量张牌。",
  ["#shine__susheng"] = "苏生：你可以消耗魔力令 %dest 回复等量体力，你摸等量的牌",
}

susheng:addEffect(fk.EnterDying, {
  anim_type = "defensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(susheng.name) and target and M.getHonor(target) == M.getHonor(player) and M.getMaryoku(player) > 0
  end,
  on_cost = function(self, event, target, player, data)
    local choices = {}
    for i = 1, M.getMaryoku(player) do
      table.insert(choices, tostring(i))
    end
    table.insert(choices, "Cancel")
    local choice = player.room:askToChoice(
      player,
      {
        choices = choices,
        skill_name = susheng.name,
        prompt = "#shine__susheng::"..target.id,
      }
    )
    if choice ~= "Cancel" then
      event:setCostData(self, choice)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local costData = event:getCostData(self)
    local num = tonumber(costData[1])
    M.changeMaryoku(player, -num ,susheng.name)
    player.room:recover{
      who = target,
      num = num,
      recoverBy = player,
      skillName = susheng.name,
    }
    if target ~= player then
      M.changeMaryoku(target, num ,susheng.name)
    end
    player:drawCards(num, susheng.name)
  end,
})

return susheng